import xlrd

import xlrd
import math
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets, linear_model
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
from sklearn.metrics import mean_squared_error, r2_score

workbook = xlrd.open_workbook('test.xlsx')
table = workbook.sheet_by_name("Sheet1")
x_old = np.array(table.col_values(2)[1:])

#方差检验
def V_analysis(list1):
    list_ = []
    for i in range(len(list1)):
        list_.append([1,100])
    print(list_)
    df = pd.DataFrame(np.array(list_),index=None)
    df.columns = ['水平', '观测值']
    print(df.head())
    formula = '{} ~ {}'.format(df.columns[1], df.columns[0])
    model = ols(formula, df).fit()
    anovat = anova_lm(model)
    print(anovat)


V_analysis(x_old)









